import "reflect-metadata"
import { DataSource } from "typeorm"
import { User } from "./entity/User"
import { IdCard } from "./entity/IdCard"
import { Department } from "./entity/Department"
import { Employee } from "./entity/Employee"
import { Article } from "./entity/Article"
import { Tag } from "./entity/Tag"
import { City } from "./entity/City"

export const AppDataSource = new DataSource({
    type: "mysql",
    host: "localhost",
    port: 3306,
    username: "root",
    password: "Lrq000905",
    database: "test-typeorm",
    synchronize: true,// 同步建表，也就是当 database 里没有和 Entity 对应的表的时候，会自动生成建表 sql 语句并执行。
    logging: true,  // logging 是打印生成的 sql 语句。
    // 1. 一对一  entities: [User , IdCard],
    // 2. 一对多  entities: [Department , Employee],
    // 3. 多对多  entities: [Article , Tag],
    
    entities: [City],
    migrations: [],
    subscribers: [], // 是一些 Entity 生命周期的订阅者，比如 insert、update、remove 前后，
    poolSize: 10, // poolSize 是指定数据库连接池中连接的最大数量。
    connectorPackage: 'mysql2',
    extra: {
        authPlugin: 'sha256_password',
    }
})
